package com.sakuraio.nextj.core.error;

import com.sakuraio.nextj.core.protocol.ErrorDetails;

/**
 * <p>Errors</p>
 *
 * @author nekoimi 2023/03/13
 */
public enum Errors implements ErrorDetails {
    // 认证异常相关
    AUTH_TYPE_NOT_SUPPORTS(10102, "认证类型不支持"),
    TOKEN_EXPIRED(10127, "认证信息已过期"),
    LOGIN_FAILED(10127, "Login failed"),
    TOKEN_CANNOT_BE_REFRESHED(10127, "Token无法刷新"),
    TOKEN_INVALID(10127, "Invalid token"),
    ACCESS_DENIED(10128, "Access denied"),

    TOKEN_HAS_BEEN_BLACKLISTED(10127, "The token has been blacklisted"),
    TOKEN_BLACK(10127, "Identity information has expired"),
    AUTHENTICATION_EXCEPTION(10401, "Not Authenticated"),
    ACCESS_DENIED_EXCEPTION(10501, "Access is denied"),

    // 请求相关
    BAD_REQUEST(10400, "Bad request"),
    UNAUTHORIZED(10401, "Unauthorized"),
    FORBIDDEN(10403, "Forbidden"),
    HTTP_NOT_FOUND(10404, "Not found"),
    METHOD_NOT_ALLOWED(10405, "Method not allowed"),

    // 请求参数错误
    REQUEST_VALIDATION(200400, "Invalid request"),

    NOT_FOUND(500404, "资源不存在!"),
    // 业务异常
    BUSINESS_EXCEPTION(500001, "业务异常"),
    // 操作异常
    OPERATION_EXCEPTION(500001, "操作异常"),
    // 客户端请求异常
    DEFAULT_CLIENT_ERROR(999400, "无效的请求！"),
    // 未捕获的异常，系统发生致命错误，提示系统维护更新!
    DEFAULT_SERVER_ERROR(999500, "系统更新中！请稍候再试～");

    private final int code;
    private final String msg;

    Errors(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public Integer code() {
        return code;
    }

    @Override
    public String msg() {
        return msg;
    }

    @Override
    public String trace() {
        return null;
    }
}
